//
//  OrganDetailView.m
//  SmartWatch
//
//  Created by zwj on 2022/11/27.
//

#import "OrganDetailView.h"

@interface OrganDetailView ()
@property(nonatomic,strong) UIView *view;
@property(nonatomic,strong) UIImageView *logoImage;
@property(nonatomic,strong) UILabel *title;
@end

@implementation OrganDetailView

- (instancetype)initWithFrame:(CGRect)frame 
{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.cornerRadius = 10;
        self.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
        self.backgroundColor = COLOR_4;
        
        UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 160)];
        [backView az_setGradientBackgroundWithColors:@[[UIColor colorWithRGB:0xC4EFEC alpha:1.0],[UIColor colorWithRGB:0xC4EFEC alpha:0.75],[UIColor colorWithRGB:0xC4EFEC alpha:0.1]] locations:@[@0.0,@0.3,@1.0] startPoint:CGPointMake(0.5, 0) endPoint:CGPointMake(0.5, 1.0)];
        [self addSubview:backView];
        
        
        MyLinearLayout *root = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
        root.myHorzMargin = 15;
        root.padding = UIEdgeInsetsMake(20, 15, 20, 15);
        root.myHeight = frame.size.height;
        root.subviewVSpace = 20;
        [self addSubview:root];
        
        MyLinearLayout *top = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
        top.myHorzMargin = 0;
        top.gravity = MyGravity_Vert_Center;
        top.myHeight = 30;
        top.subviewHSpace = 10;
        [root addSubview:top];
        
        {
            UIView *view = [[UIView alloc]init];
            view.mySize = CGSizeMake(30, 30);
            ViewCorner(view, 15);
            [top addSubview:view];
            self.view = view;
            
            UIImageView *logoImage = [[UIImageView alloc]initWithFrame:CGRectMake(4, 4, 24, 24)];
            [view addSubview:logoImage];
            self.logoImage = logoImage;
            
            UILabel *title = [UILabel createLabelText:@"" font:UIFontMake(18) textColor:COLOR1515];
            title.mySize = kAutoSize;
            [top addSubview:title];
            self.title = title;
        }
        
        UIScrollView *scrollView = [[UIScrollView alloc]init];
        scrollView.showsVerticalScrollIndicator = NO;
        scrollView.myHorzMargin = 0;
        scrollView.weight = 1;
        [root addSubview:scrollView];
        
        MyLinearLayout *content = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
        content.myHorzMargin = 0;
        content.myHeight = kAutoHeight;
        content.subviewVSpace = 20;
        [scrollView addSubview:content];
        
        NSArray *array = @[@"",@"",@"",@"",@""];
        for (int i = 0; i < array.count; i++) {
            MyLinearLayout *hort = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
            hort.myHorzMargin = 0;
            hort.gravity = MyGravity_Vert_Center;
            hort.myHeight = 56;
            hort.backgroundColor = COLOR_4;
            hort.padding = UIEdgeInsetsMake(0, 15, 0, 15);
            hort.layer.cornerRadius = 6;
            hort.subviewHSpace = 10;
            hort.layer.shadowColor = [UIColor colorWithRed:222/255.0 green:238/255.0 blue:238/255.0 alpha:0.8000].CGColor;
            hort.layer.shadowOffset = CGSizeMake(0,1);
            hort.layer.shadowOpacity = 1;
            hort.layer.shadowRadius = 8;
            hort.tag = 100 + i;
            [content addSubview:hort];
            [hort setTarget:self action:@selector(itemClick:)];
            
            UIView *dian = [UIView new];
            dian.mySize = CGSizeMake(8, 8);
            dian.backgroundColor = THEME_COLOR;
            ViewCorner(dian, 4);
            [hort addSubview:dian];
            
            UILabel *title = [UILabel createLabelText:@"大脑" font:UIFontBoldMake(17) textColor:COLOR1515];
            title.mySize = kAutoSize;
            [hort addSubview:title];
            
            UILabel *time = [UILabel createLabelText:@"nerves of back" font:UIFontMake(12) textColor:COLOR999];
            time.myHeight = kAutoHeight;
            time.weight = 1;
            [hort addSubview:time];
            
            UIImageView *right = [[UIImageView alloc]initWithImage:UIImageMake(@"icon_arrow_right")];
            right.mySize = CGSizeMake(16, 16);
            [hort addSubview:right];
            
        }
        
    }
    return self;
}
- (void)setImageStr:(NSString *)imageStr {
    self.logoImage.image = UIImageMake(imageStr);
}
- (void)setColor:(UIColor *)color {
    ViewBorder(self.view, 1, color);
}
- (void)setName:(NSString *)name {
    self.title.text = [name substringToIndex:name.length - 1];
}

- (void)itemClick:(UIView *)view {
    NSInteger tag = view.tag - 100;
    !self.itemClick?:self.itemClick(tag);
}
@end
